Java - lol PDF

Title Java - lol
Course k099
Institution Université Saint-Esprit de Kaslik
Pages 11
File Size 162.7 KB
File Type PDF
Total Downloads 30
Total Views 148

Summary

lol...


Description

package hihi; public class Jojop { public static void main(String[] args) { // TODO Auto-generated method stub int x=5; System.out.println("x="+x); System.out.println("x+3="+(x+3) ); System.out.println("x+3=" +x + 3); } }

package conditions; import java.util.Scanner; public class exercise2 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner kb = new Scanner(System.in); System.out.println("Please enter an integer x such that x is odd:"); System.out.println("Please enter an integer y such that y is odd:"); System.out.println("Please enter an integer z such that z is even:"); int x = kb.nextInt(); //x is odd int y = kb.nextInt(); //y is odd int z = kb.nextInt(); //z is even if ( x%2 == 0 && y%2 == 0 && z%2 == 1) System.out.println("False"); else { System.out.println("True");

if (z == x+y) System.out.println("Correct"); else System.out.println("Incorrect");

package conditions; import java.util.Scanner; public class Exercise3 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner kb = new Scanner(System.in); System.out.println("Please enter a stricty positive integer x:");

int x = kb.nextInt(); //x>0 System.out.println("Please enter a stricty positive integer y:"); int y = kb.nextInt(); //y>0 System.out.println("Please enter a stricty positive integer z:"); int z = kb.nextInt(); //z>0 double sum = (1.0/x +1.0/y +1.0/z); if (x=600) System.out.println("Your bill is: "+bill3 +"$");

} } } } } }

package your; import java.util.Scanner; public class Calculator { public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Hello User!"); System.out.println("Please, give me 2 integers:"); Scanner kb = new Scanner(System.in); int x = kb.nextInt(); int y = kb.nextInt(); int sum =x+y; System.out.println("Their sum is:" +sum); int difference =x-y; System.out.println("Their difference is:" +difference); int product =x*y; System.out.println("Their product is:" +product); int division =x/y; System.out.println("Their division is:" +division); int remainder =x%y; System.out.println("Their remainder is:" +remainder);

System.out.println("The average is:"+((double)(x+y)/2));

package your; import java.util.Scanner; public class MondayClass { public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("What is your current age?"); Scanner kb = new Scanner(System.in); int x = kb.nextInt(); System.out.println("Your age in ten years will be:" +(x+10));

} } package your; import java.util.Scanner; public class TimeConversion { public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Hello User!"); System.out.println("Please, give me 2 integers:"); Scanner kb = new Scanner(System.in); int x = kb.nextInt(); int y = kb.nextInt(); System.out.println(x + "+" +y + "=" +(x+y) ); System.out.println(x + "-" +y + "=" +(x-y)); System.out.println(""+(x/y)); System.out.println(""+(x*y)); System.out.println(""+(x%y)); } } package helloworld; public class Welcome { public static void main(String[] args) { // TODO Auto-generated method stub int n=2; int p=4; int k=3; System.out.print(k += p++ + ++n +p ); } } package Fall; public class GHIHI { public static void main(String[] args) { // TODO Auto-generated method stub int x; int y; x=6 ; y=7 ; System.out.println("The result is "+x/y);

} }

package calculator; import java.util.Scanner; public class calculator { public static void main(String[] args) { // TODO Auto-generated method stub Scanner kb = new Scanner(System.in); System.out.println("Kindly enter an operation of length 5:"); String input = kb.nextLine(); int n = input.length(); System.out.println("The length of your string is:"+n); int p = Integer.parseInt("input"); if (n != 5 ) System.out.println("Error"); else System.out.println("The result is "+p);

} }

package calculator; import java.util.Scanner; public class time { public static void main(String[] args) { // TODO Auto-generated method stub Scanner kb = new Scanner(System.in); System.out.println("Please enter the first time in military format"); String time1 = kb.nextLine(); System.out.println("Please enter the second time in military format"); String time2 = kb.nextLine();// the first two numbers represent the working hours and the last two represent the number of working minutes if (time1.length() != 4) System.out.println("Wrong time"); else {

String int n1 String int n2

s1 = time1.substring(0, 2); = Integer.parseInt(s1); s2 = time2.substring(0,2); = Integer.parseInt(s2);

String int n3 String int n4

s3 = time1.substring(2,3); = Integer.parseInt(s3); s4 = time2.substring(2,3); = Integer.parseInt(s4);

System.out.println("The time is " +(n2-n1) +" hours" +" and "+ (n4-n3)+" minutes"); } } }

package strings; import java.util.Scanner; public class Names1 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner kb = new Scanner(System.in); System.out.println("Kindly state your full name:"); String name = kb.nextLine(); System.out.println("Your name's length is: " + name.length()); System.out.println("Your name in capital letters is:" + name.toUpperCase()); System.out.println("Your name in lowercase is:" + name.toLowerCase()); int p = name.indexOf('a'); if (p==-1) System.out.println("Error"); else System.out.println("The position of a is"+p); String s2 = "geo"; if (name.startsWith(s2)) System.out.println("OK"); else System.out.println("NO"); System.out.println("Kindly enter one of the letters included in your name: "); char letter = kb.next().charAt(0); String name1 = name.replace(letter , 'a'); System.out.println("By replacing that letter in your name, it will become:" + name1);; String firstname = name.substring(0, name.indexOf(' ')); System.out.println("Your first name is: " +firstname);

} }

package shrodinger; import java.util.Scanner; public class strings { public static void main(String[] args) { // TODO Auto-generated method stub Scanner kb = new Scanner(System.in); System.out.println("Enter a word:"); String s1 = kb.next(); int n = s1.length(); System.out.println("The length of your word is "+n); System.out.println("Enter another word:"); String s2 = kb.next(); int y = s2.length(); System.out.println("The length of your word is "+n); int r = s1.compareTo(s2); System.out.println("The difference between your words is "+r);

} } package TimeConversion; import java.util.Scanner; public class convertingtime1 { public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Hello User!"); System.out.println("Kindly enter the time 3456789 and I'll convert it for you from minutes to years and days."); Scanner kb = new Scanner(System.in); int x= kb.nextInt(); // x is the time in minutes int y = x/525600; // y is the time in years int z1; // z1 is the remaining time in days int r = x - 525600*y; //r is the remaining time in minutes

z1 = r/1440; System.out.print("The time in days and years is "+y); System.out.print(" years"); System.out.print(" and "+z1); System.out.println(" days.");

package TimeConversion; public class convertingtime3 { public static void main(String[] args) { // TODO Auto-generated method stub int x= 3456789; System.out.println("The time in minutes is "+x +"."); int y= 525600; int years = x/y; // let y represent the number of minutes in a year int remainder = x%y; int days = (x%y)/1440; System.out.println("Its equivalent in days and years is "+years + " years and "+days +" days" +".");

} } package TimeConversion; import java.util.Scanner; public class convertingtimesolution { Scanner kb = new Scanner(System.in); public static void main(String[] args) { // TODO Auto-generated method stub Scanner kb = new Scanner(System.in); System.out.print("Input the number of minutes: "); int min = kb.nextInt(); int years = min / (24*60*365); int days = min / (60*24) % 365; System.out.println(min + " minutes is approximately:" + years +" years and " + days +" days" +"."); } }

package TimeConversion; import java.util.Scanner; public class solution {

public static void main(String[] args) { // TODO Auto-generated method stub Scanner kb = new Scanner(System.in); System.out.print("Input the number of minutes: "); int min = kb.nextInt (); int years = min / (60 * 24 * 365); in a year int days = (min / 60 / 24) % 365;

//

60 * 24 * 365 : number of minutes

// min / 60 / 24 : total number of days

System.out.println( min + " minutes is approximately " + years + " years and " + days + " days"); } }...


Similar Free PDFs