Lab-1 Write a complete java program to print your name 10 times using For statem
ID: 3631685 • Letter: L
Question
Lab-1
Write a complete java program to print your name 10 times using
For statement (loop).
Lab-2
Write a complete java program to print your name 10 times using
while statement (loop).
Lab-3
Write a complete java program to make an Address Label.
Your program should get
First Name:
Last Name;
St. Address
City , State and Zip code
Then print
Last Name First name
St address Followed by City State
Zip
Print it 5 times.
Lab-4
Write a complete java program to print weather condition base on
Temperature Degree. If d Temperature is greater than 95 displays outside is very hot
If Temperature is between 85 and 94 display time to swim.
75-83 ….
Explanation / Answer
Please Rate:Thanks
The programs will help you
Lab-1
import java.util.Scanner;
public class printnameusefor {
public static void main(String[] args){
Scanner input=new Scanner(System.in);
System.out.println("Enter name ");
String s=input.next();
System.out.println("Display name 10 times using for loop ");
for(int i=1;i<=10;i++)
System.out.println(s);
}
}
----------------------------------------------------------------------------------------
Output:
Enter name
Cramster
Display name 10 times using for loop
Cramster
Cramster
Cramster
Cramster
Cramster
Cramster
Cramster
Cramster
Cramster
Cramster
BUILD SUCCESSFUL (total time: 4 seconds)
------------------------------------------------------------------------------------------
Lab-2
import java.util.Scanner;
public class printnameusewhile {
public static void main(String[] args){
int i=1;
Scanner input=new Scanner(System.in);
System.out.println("Enter name ");
String s=input.next();
System.out.println("Display name 10 times using for loop ");
while(i<=10){
System.out.println(s);
i++;
}
}
}
------------------------------------------------------
Output:
Enter name
Hello
Display name 10 times using for loop
Hello
Hello
Hello
Hello
Hello
Hello
Hello
Hello
Hello
Hello
BUILD SUCCESSFUL (total time: 4 seconds)
---------------------------------------------------------------------------------
Lab-3
import java.util.Scanner;
public class printnaddressusedowhile{
public static void main(String[] args){
int i=1;
Scanner input=new Scanner(System.in);
System.out.println("Enter First name ");
String fname=input.next();
System.out.println("Enter Last name ");
String lname=input.next();
System.out.println("Enter street address ");
String street=input.next();
System.out.println("Enter city name ");
String city=input.next();
System.out.println("Enter State ");
String state=input.next();
System.out.println("Enter Zip code");
int zip=input.nextInt();
System.out.println("Address printed 5 times ");
do{
System.out.println(lname+" "+fname);
System.out.println(street+", "+city+", "+state);
System.out.println(zip);
i++;
}while(i<=5);
}
}
-------------------------------------------------
Output:
Enter First name
Sunitha
Enter Last name
P
Enter street address
MainRoad
Enter city name
Nuzvid
Enter State
AndhraPradesh
Enter Zip code
521201
Address printed 5 times
P Sunitha
MainRoad, Nuzvid, AndhraPradesh
521201
P Sunitha
MainRoad, Nuzvid, AndhraPradesh
521201
P Sunitha
MainRoad, Nuzvid, AndhraPradesh
521201
P Sunitha
MainRoad, Nuzvid, AndhraPradesh
521201
P Sunitha
MainRoad, Nuzvid, AndhraPradesh
521201
BUILD SUCCESSFUL (total time: 25 seconds)
--------------------------------------------------------
Lab-4
import java.util.Scanner;
public class printnameusefor {
public static void main(String[] args){
int temp;
Scanner input=new Scanner(System.in);
System.out.println("Enter Temperature ");
temp=input.nextInt();
if(temp>95)
System.out.println("Outside is very hot");
else if(temp>85 && temp<94)
System.out.println("Time to swim ");
else if(temp>75 && temp<83)
System.out.println("Outside is dry");
else
System.out.println("Outside is cool");
}
}
-----------------------------------------------------
Output:
Enter Temperature
97
Outside is very hot
BUILD SUCCESSFUL (total time: 8 seconds)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.