8:08 As I am from python lang. , I knew that strings can be separated inside the print statement by commas(,), but in JAVA now I came to know that + is to be given to separate two strings in the print statement. Thanks a lot for it , btw as I got error in that separation of strings I tried a new method which I want to share. System.out.print("Enter your name:"); String str1 = S.next(); System.out.print("Hello,"); System.out.print(str1); System.out.print(" Have a nice day"); Thought of making in the same line which is required in the output , which can be done by just removing ln from print statement, so I did like that. I hope if anyone is seeing can understand it along with it's essence. Thanks a lot Harry .❤❤
Thanks bro, I came from C++ background and I have been trying to use , to separate a string and a pre defined literal. 😂 But it never worked. Today I knew we have to use + 😅❤
9:13 I did the same using different method , took a bool value and then checked it. Anyways , directly putting the condition in the print statement is also not bad. My answer:- System.out.println("Enter an integer:"); boolean b= S.hasNextInt(); System.out.println(b); Thanks a lot , Harry.
repect: Printf("Sir Please Continue Teaching us ."); If(Sir You continue Taching us){ HappY Teachers Day Sir ..Wish You all the best for you hard work.. And keep it up sir }else{ goto repect; }
Hello harry bhai ... I'm a government employee in municipal corporation jaipur ... I'm want to tell you that how i found you ... Ek bar me MLA election duty me gaya tha wha mujhe ek banda mila usne mujhe pucha ki kya krte ho study me kya interest h to mene use bataya ki mujhe programming language padhni he jo mere liye hacking me bahit kam aayegi to usne bataya ki RU-vid pr ek channel h code with harry naam se ek bar check krna ....harry bhai tb se me aapke videos dekh rha hu or apki playlist bhi access kr rkhta hu ...you are one of my favorite ❤️
I am watching your java video just before a month .it's awesome👍👍😊😊😊 for understanding from beginners level to higher level... and I also finish half century play list both java&html-css-javascript
8:30 Float can't be used here . As the mile conversion unit is a long decimal , so Double is to used here for our convenience. I did float input in Km to m, but it came as error in conversion of Km to miles , so I came to know of my another mistake here. System.out.println("Enter Distance in Kilometers:"); double a=S.nextDouble() ; double b = a*0.621371; System.out.println("Distance in miles is:"); System.out.println(b); Got the correct answer now. Thanks a lot, Harry brother Edit : float can also be done
4:17 Yes , float/double should be used . I did the same mistake when I was solving the question of last challenge (5 subjects CGPA). I then thought of the decimal answer and then converted each input into float data type. IDK why you are not taking user input process but that is the actual process which everyone should follow , although by taking direct input it will be easy for the beginners. P.S. :- I am basically used to python so there float or int , data type doesn't matter, so I generally thought if taking data input as int from the user which is wrong. Thanks .❤❤
Can you help me? I took input in integer and I made two variables which hold value total marks of exam and total marks obtained, then I made an integer variable to calculate percentage but when I am using int, it is showing zero everytime but when I use float then the same exact program is working, why and how? I input marks according to that it make 90 percent but it works in float but not in int 😢
System.out.println("how many number of kilometers you want to convert in miles"); Scanner s = new Scanner(System.in); double kilometers = s.nextDouble(); System.out.println("MILES =" + kilometers* 0.621); this is how i did my code . The value of miles is approximate
Since 1 km = 0.621 , we see some decimal numbers here, by which we understood that we are going to deal with decimals in this code. So the data type related to decimals can be float or double. Tip = when finding CGPA or percentage, we know we are gonna get our answer in decimals, so for such type of questions we always use float or double.
Sir actually I am learning java from your video in 2021 and I had seen all the lectures and I had solve the problem which asked in lecture 5 by my own kindly look into it and correct it if l had done any error in it
double km = 1; double miles = 0.621371; System.out.println("Enter kilometers"); Scanner sc = new Scanner(System.in); double kms = sc.nextDouble(); double output = kms*miles; System.out.println(output); } } It took all my brain power so i suggest revision after every letcure is must. Happy Programming😄
8:26 OMG F . I had done this one as Km to m day before yesterday while practice. Going to try now. THIS IS WHY QUESTION READING SHOULD BE DONE THOROUGHLY. Sorry to myself as well as to Harry for not reading the question correctly, although I have applied the same concept there which is to be done. Going to change it now. Will come and share the answer.
2:20 But the same can be done by taking user input . You had did the same thing while telling us about data types but it was acceptable then as we had not learnt about the user input. But as we know we should take user input (user's choice of integers), and then run the program.
// Question 4 System.out.println("Program to convert Kilometers into Miles"); System.out.println("Enter the Number of Kilometers you want to convert into miles"); Scanner sc = new Scanner(System.in); float kilo = sc.nextInt(); float m = kilo/1.609f; System.out.println( kilo + " is converted into miles it comes to be: " + m); // Love You Harry Bhai ♥
@@itachi_terabapp bro can u tell me in 3rd program he didn't use import. Until.scanner but before when he teaching us about how to take input from keyboard he used that one reply bro
done harry bro import java.util.Scanner; public class practiceS1 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("enter the kilometer to convert"); float kilo = sc.nextFloat(); float mile = (kilo/1.609344F); System.out.println(mile + " miles"); }
System.out.println("Enter km which you want to convert into miles"); Scanner sc = new Scanner(System.in); float km1 = sc.nextFloat(); float aa = km1*0.621371f; System.out.println(aa);
Anwser of question 4 Scanner sc = new Scanner(System.in); System.out.println("write the value of kilometer"); Float km = sc.nextFloat() Float mile = km*0621371f; System.out.println(mile + " miles");
My school's computer teacher- Children now we are going to learn java. Me - How will i learn java now as my sir teaches only the theory part in the classes and gives practicals in exam..😢😢 Harry sir - Full java tutorial for beginners. Me - 😍😍😍😍😎 Now i can learn java very easily.
Question 4: Write a java program to covert kilometers to miles System.out.println("Enter the value in kilometers"); Scanner sc = new Scanner(System.in); double value = sc.nextInt(); double miles = (value/1.609); System.out.println("The value in miles is " + miles + " miles");
time stamp : 8:24 import java.util.Scanner; public class Main { public static void main(String[] args) { float kilo,miles; Scanner sc = new Scanner(System.in); System.out.println("enter the kilometers"); kilo=sc.nextFloat(); System.out.println("Conversion begins : "); miles=kilo*0.62137119f; System.out.print(miles); } }
@@siddhant886 Bht easy hai bhai...ap km to miles conversion formula google se dekhey or Wohi formula use krein...or jis variable k ander calculation store kia us variable ko print krva dey
7 August Completing in a row with revision . Will complete it ASAP and move on . Already wasted a lot of time on this , basic course , which is made for kids only. No hate but after using for a month , I realized that CWH is known for making content which are helpful for kids. Thanks Harry...
4th Quetion : My approach :) import java.util.Scanner; public class Main{ public static void main(String[] args){ System.out.println("Enter the value in kilometers"); Scanner sc = new Scanner(System.in); double km = sc.nextDouble(); double mile = (km/1.609); System.out.println("The value of Kilometers in miles is "+ mile); } }
8:35 Here I have used another logic i.e. I have taken user input , then stored boolean b= sc.hasNextInt() , then System.out.println(b). And got the same result .
Question No.4 :- import java.util.Scanner; public class CWH_Ch1_PS2 { public static void main(String[] args){ System.out.println("Enter The Kilometers "); Scanner sc = new Scanner(System.in); float km = sc.nextFloat(); float miles = (float) (km/1.609); System.out.println("The Kilometers in Miles is" + miles + " Miles");
It's working 😊😊 import java.util.Scanner; public class KING_06 { public static void main(String[ ] args) { System.out.println("Change Kilometer into Miles"); Scanner sc = new Scanner(System.in); double kilo = sc.nextDouble( ); double miles = (kilo)*0.621371; System.out.println(miles); } }
Hello harry bhaiya maine sare question apne se banaya pahle ek do bar error aaya par last me sare question bna liye thank you so much bhaiya aapne itne achhe se samjhaya 😊
8:29 - Question 4 Here is the code , import java.util.Scanner; public class Length { public static void main (String[ ] args) { Scanner k = new Scanner (System.in); System.out.print("Enter Length in Kilometers = "); double kilometers = k.nextDouble(); double miles = kilometers/1.609; System.out.println("Length in miles = "+miles+" mi"); } }
{ Scanner sc4 = new Scanner(System.in); System.iut.println("Enter your Kilometers "); float KM = sc4.next(); double Miles = KM * 0.6213712; System.out.println(Conversation of KM to Miles is"); }
sir humne int data type ka use kiya h and int data type is onl;y for integer that"s why its output is an integer. We have to use Double data type. thnks a lot sir #CodeWithHarry❤
Hello harry sir! I just want to ask that the CGPA of the numbers (in the seventh video) is equal to: 7.33 because the grade point for 49=6 ; that for 95= 10; & that for 48 = 6 .so when we add ie. 6+10+6 and divide it by 3 we get 7.333333333. am I correct?
Harry bhai aapne question 5 waala concept (system.out.println(sc.hasnextInt());) toh pehle btaya nhi ki kaise use krna h.. BTW I love ❤️ this playlist 😇🙌🏻.
Import java.util.Scanner ; class Main { public static void main(String[] args) { System.out.println(" km into miles"); Scanner km = new Scanner(System.in); System.out.println("kilometers here"); float a = km.nextFloat(); System.out.println(a /1.609); } }
practice 1 and 2 are very easy i can do it orally now thanks harry Practice set 3 here is the code i wrote import java.util.Scanner; public class practiceSet1 { public static void main(String[] args) { Scanner scanningName = new Scanner(System.in); System.out.print("Enter Your name: "); String name = scanningName.next(); System.out.println(" "); System.out.print("Hello "); System.out.print(name); System.out.print(" have a good day"); } }
Hello! Bro first of all thank you so much for teaching me java so well not just for java. If I have any question, I immediately go to your channel and solve the doubt. Thanks once again bro love you. import java.util.Scanner; public class percentage { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter the Mathematics Marks"); int M = sc.nextInt(); System.out.println("Enter the Science Marks"); int S = sc.nextInt(); System.out.println("Enter the Physics Marks"); int P = sc.nextInt(); System.out.println("Enter the Chemistry Marks"); int C = sc.nextInt(); System.out.println("Enter the English Marks"); int E = sc.nextInt(); System.out.println("Enter the Sanskrit Marks"); int F = sc.nextInt(); System.out.println("percentage of Student"); float B = (M + S + P + C + E + F) / 6f; System.out.println(B); System.out.println("Enter Student name"); String name = sc.next(); if (B > 30){ System.out.println("\u001B[92m" + "Hello " + name + " Congratulation You have a pass this exam 😀!"); } else { System.out.println("\u001B[91m" + "Hello " + name + " You have a Fail this exam ☹!"); } } }
My code to convert kilometers to miles:- System.out.println("Enter value of kilometers:- "); Scanner sc = new Scanner(System.in); int KM = sc.nextInt(); float miles = 0.62f; System.out.println(KM + " Kilometers is equal to: " + KM*miles + " miles");
@@suhanipachouri5416 0.62f coz 1km = 0.62 miles, and the "f" (0.62f) because java understands that the variable is a float when we add the letter f in the end... 🙂
Hi ! Why haven’t you defined the scanner function ie: (import java.util.Scanner ) before public class , as u have directly created the object of scanner in main function
//Question 1 public class PracticeSet1 { public static void main(String[]Args){ int a = 100; int b = 250; int c = 900; int sum = a + b + c; System.out.println("The sum of the three numbers is :"); System.out.println(sum); } } Output : "C:\Program Files\Java\jdk-22\bin\java.exe" "-javaagent:C:\Users\PRATYUSH TRIPATHY\AppData\Local\Programs\IntelliJ IDEA Community Edition\lib\idea_rt.jar=54713:C:\Users\PRATYUSH TRIPATHY\AppData\Local\Programs\IntelliJ IDEA Community Edition\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath "C:\Users\PRATYUSH TRIPATHY\IdeaProjects\JAVA\out\production\JAVA" PracticeSet1 The sum of the three numbers is : 1250 Process finished with exit code 0 //Question 2 public class PracticeSet1 { public static void main(String[]Args){ float physics = 90; float chemistry = 70; float maths = 75; float cgpa = (physics + chemistry + maths)/30; System.out.println("The cgpa is :"); System.out.println(cgpa); } } "C:\Program Files\Java\jdk-22\bin\java.exe" "-javaagent:C:\Users\PRATYUSH TRIPATHY\AppData\Local\Programs\IntelliJ IDEA Community Edition\lib\idea_rt.jar=55272:C:\Users\PRATYUSH TRIPATHY\AppData\Local\Programs\IntelliJ IDEA Community Edition\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath "C:\Users\PRATYUSH TRIPATHY\IdeaProjects\JAVA\out\production\JAVA" PracticeSet1 The cgpa is : 7.8333335 Process finished with exit code 0 //Question 3 import java.util.*; public class PracticeSet1 { public static void main(String[]Args){ System.out.println("What is your name ??"); Scanner sc = new Scanner(System.in); String name = sc.next(); System.out.println(" Hello " + name + " have a good day. "); } } Output : "C:\Program Files\Java\jdk-22\bin\java.exe" "-javaagent:C:\Users\PRATYUSH TRIPATHY\AppData\Local\Programs\IntelliJ IDEA Community Edition\lib\idea_rt.jar=55631:C:\Users\PRATYUSH TRIPATHY\AppData\Local\Programs\IntelliJ IDEA Community Edition\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath "C:\Users\PRATYUSH TRIPATHY\IdeaProjects\JAVA\out\production\JAVA" PracticeSet1 What is your name ?? Ram Hello Ram have a good day. Process finished with exit code 0 // Question 4 import java.util.*; public class PracticeSet1 { public static void main(String[]Args){ System.out.println("Enter distance in kilometers :"); Scanner sc = new Scanner(System.in); float km = sc.nextFloat(); float miles = km*0.62137119F; System.out.println("The result of the conversion is :"); System.out.println(miles); } } Output : "C:\Program Files\Java\jdk-22\bin\java.exe" "-javaagent:C:\Users\PRATYUSH TRIPATHY\AppData\Local\Programs\IntelliJ IDEA Community Edition\lib\idea_rt.jar=56009:C:\Users\PRATYUSH TRIPATHY\AppData\Local\Programs\IntelliJ IDEA Community Edition\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath "C:\Users\PRATYUSH TRIPATHY\IdeaProjects\JAVA\out\production\JAVA" PracticeSet1 Enter distance in kilometers : 10 The result of the conversion is : 6.213712 Process finished with exit code 0 // Question 5 import java.util.*; public class PracticeSet1 { public static void main(String[]Args){ Scanner sc = new Scanner(System.in); System.out.println("Enter your number :"); System.out.println(sc.hasNextInt()); } } Output : "C:\Program Files\Java\jdk-22\bin\java.exe" "-javaagent:C:\Users\PRATYUSH TRIPATHY\AppData\Local\Programs\IntelliJ IDEA Community Edition\lib\idea_rt.jar=56250:C:\Users\PRATYUSH TRIPATHY\AppData\Local\Programs\IntelliJ IDEA Community Edition\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath "C:\Users\PRATYUSH TRIPATHY\IdeaProjects\JAVA\out\production\JAVA" PracticeSet1 Enter your number : 40 true Process finished with exit code 0
Hi Harry! I just started Java Programming by viewing this playlist. And I had done Question 4 by this type // Question 4 System.out.println("Write in Kilometers: "); Scanner sc=new Scanner(System.in); double Km= sc.nextDouble(); double Miles=Km*0.62; System.out.println("You have to go "+Miles+" miles more"); And O/p comes: Write in Kilometers: 8.75 You have to go more 5.425 miles Process finished with exit code 0
thank you so much for videos here is my solution.. import java.util.Scanner; public class marksintopercentage { public static void main(String[] arg) { System.out.println("Enter marks of 5 subjects"); Scanner sc=new Scanner(System.in); System.out.println("enter marks of 1st subject"); float a = sc.nextFloat(); System.out.println("enter marks of 2nd subject"); float b = sc.nextFloat(); System.out.println("enter marks of 3rd subject"); float c = sc.nextFloat(); System.out.println("enter marks of 4th subject"); float d = sc.nextFloat(); System.out.println("enter marks of 5th subject"); float e = sc.nextFloat(); System.out.println("enter maximum marks"); float g= sc.nextFloat(); float marks = g*5; System.out.println("the percentage of student is "+(((a+b+c+d+e)/marks)*100+"%")); } }
4:34 total marks is 300 , so 100 is to be multiplied so here it's a mistake . I think . If it's to be done in correct way I think just divide the total marks secured by 3 . So, simple. And here I had also done this mistake, I had not taken float at first but then I changed the whole program into float user inputs.
// practice set 1 Q4 import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); System.out.println("Enter kilometres Covered"); float km = sc.nextFloat(); System.out.println(km); double miles = km * 0.621371; System.out.println("You Have Covered " + miles + " miles"); } }
// Question 4 // Kilometres to miles // float mile = 0.6214f; // System.out.println("Write the value in kms which you want to convert into miles"); // Scanner sc = new Scanner(System.in); // float km = sc.nextInt(); // float ans = km*mile; // System.out.println(km + " km in miles = " + ans);
The solutions of practise set : The solutions of answer number 1: package java_programming; import java.util.Scanner; public class hello { public static void main(String[] args) { Scanner s=new Scanner (System.in); System.out.print("enter your first number: "); int a=s.nextInt(); System.out.print("enter your second number: "); int b=s.nextInt(); System.out.print("enter your third number: "); int c=s.nextInt(); System.out.print("sum of three numbers is: "); System.out.print(a+b+c); s.close(); } } the answer of question number 4 is: package java_programming; import java.util.Scanner; public class hello { public static void main(String[] args) { Scanner s= new Scanner(System.in); System.out.print("enter distance (in km): "); int a= s.nextInt(); System.out.print(a); System.out.print(" km is equal to "); System.out.print(a*0.62137119224); System.out.print(" miles."); s.close(); } } the answer of question number 5 is: package java_programming; import java.util.Scanner; public class hello { public static void main(String[] args) { Scanner s= new Scanner(System.in); System.out.print("enter your number:"); int num = s.nextInt(); System.out.print("you entered an integer."); s.close(); } } the answer of question no 3 is: package java_programming; import java.util.Scanner; public class hello { public static void main(String[] args) { Scanner s= new Scanner(System.in); System.out.print("enter your name:"); String str = s.next(); System.out.print("Hello "+str+" ,have a good day."); s.close(); } } the answer of question number 2 is: package java_programming; import java.util.Scanner; public class hello { public static void main(String[] args) { Scanner s=new Scanner (System.in); System.out.print("enter your first subject: "); int a=s.nextInt(); System.out.print("enter your second subject: "); int b=s.nextInt(); System.out.print("enter your third subject: "); int c=s.nextInt(); System.out.print("cgpa is: "); System.out.print((a+b+c)/30.0); s.close(); } }
6:30 I didn't know about how to concatenate strings in JAVA while printing , so I used a different logic for it. Just removed ln from System.out.println() , then printed Hello , then, str(My name being stored in it), then again in another print statement , the rest of it. So, all of them came in a similar manner P.S. :- In python, it was , whereas here it's +
Challenge Accepted Solution : - // Question4 System.out.println("Enter the value of Miles"); Scanner sc = new Scanner(System.in); Double Miles = sc.nextDouble(); Double kiloMeteres = 1.60934; Double Value = (kiloMeteres*Miles); System.out.println(Value);
System.out.println("enter the value"); float a = sc.nextFloat(); double miles = a*0.621; System.out.print("the value of km in miles is = "); System.out.print(miles); Thanks me later😅
ALL FIVE QUESTION ANSWERS: Q1:) import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter first number:"); int s1 = sc.nextInt(); System.out.print("Enter second number:"); int s2 = sc.nextInt(); System.out.print("Enter third number:"); int s3 = sc.nextInt(); int sum = s1+s2+s3; System.out.println("sum of three number is:" +sum); } } Q2:) import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter first subject marks:"); float s1 = sc.nextInt(); System.out.print("Enter second subject marks:"); float s2 = sc.nextInt(); System.out.print("Enter third subject marks:"); float s3 = sc.nextInt(); float cgpa = (s1+s2+s3)/30; System.out.println("cgpa is:" +cgpa); } } Q3:) import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter your name:"); String name = sc.next(); System.out.print("Hello " +name +" have a good day"); } } Q4:) import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter distance(in km):"); int km = sc.nextInt(); double miles=km * 0.621371; System.out.print("distance (in miles) is :" +miles); } } Q5:) import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter a number:"); Boolean num = sc.hasNextInt(); System.out.print(num); } }
import java.util.Scanner; public class practise{ public static void main(String [] args){ Scanner sc = new Scanner(System.in); System.out.println("Enter length in kilometer:"); double km = sc.nextDouble(); double miles = (km/1.609); System.out.println("The length in miles is " +miles); } } This is the solution of question no 4 sir!
01:20 Share a practice set for Java with solution 02:40 Practice problems in chapter 1 involve summing 3 numbers. 04:00 Calculate CGPA for 3 subjects with Java programming 05:20 Dividing integer by integer yields integer result 06:40 Floating point numbers are used to handle decimal results 08:00 Create a Java program to ask for user's name and greet 09:20 Demonstration of concatenation in Java and basic string operations. 10:36 Determining if an integer is present in the input
public static void main(String[] args) //question 4 System.out.println (^ convert kilometers to miles "); Scanner s = new Scanner (sys ); System.out.println(" enter km^ n ); float a = oat(); double b = (a/1.609); System.out.println(b);
// QUESTION 2; double num1 = 85; double num2 = 67; double num3 = 45; double cgpa = (num1+num2+num3)/3; System.out.println(cgpa); // We can use double also in place of float
Hi, Harry. As i am a beginner, and firs time i am learning java. so what ever code I have written by myself. Please correct me if I am wrong. package CHW_05_Exercise; import java.util.Scanner; public class ScannerClass { public static void main(String[] args) { Scanner student = new Scanner(System.in); System.out.print("The mark of the student in english :"); int eng = student.nextInt(); System.out.print("The mark of the student in science :"); int sci = student.nextInt(); System.out.print("The mark of the student in mathematics :"); int math = student.nextInt(); System.out.print("The mark of the student in social :"); int social = student.nextInt(); System.out.print("The mark of the student in assamese :"); int ass = student.nextInt(); System.out.print("The mark of the student in Total marks :"); int total = student.nextInt(); System.out.print("The mark for each subject is :"); int eachSub = student.nextInt(); float a = (eng + sci + math + social + ass); float b = a / total; float percentage = b * eachSub; System.out.println("The percentage of the student is :" + percentage); } }