Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Lab3
- // Problem 1
- import java.util.Scanner;
- class Problem1{
- public static void main(Strings args[]){
- Scanner sc=new Scanner(System.in);
- int num=sc.nextInt();
- int remainder=0;
- while(num>0){
- remainder=remainder*10+(num%10);
- num/=10;
- }
- System.out.print(remainder);
- }
- }
- // Problem 2
- import java.util.Scanner;
- class Problem2{
- public static void main(String args[]){
- Scanner sc=new Scanner(System.in);
- int num=sc.nextInt();
- int remainder=0, output=0;
- int power=1;
- while (num>0){
- remainder=num%2;
- output+=remainder*power;
- num/=2;
- power*=10;
- }
- System.out.print(output);
- }
- }
- // Problem 3
- import java.util.Scanner;
- class Problem3{
- public static void main(String args[]){
- Scanner sc=new Scanner(System.in);
- int num=sc.nextInt();
- int power=1, output=0;
- for (int i=0; i<6; i++){
- output+=(num%10)*power;
- power*=2;
- num/=10;
- }
- System.out.print(output);
- }
- }
- // Problem 4 (using toLowerCase())
- import java.util.Scanner;
- class Problem4{
- public static void main(String args[]){
- Scanner sc=new Scanner(System.in);
- String s=sc.nextLine();
- String t=s.toLowerCase();
- System.out.print(t);
- }
- }
- // Problem 4 (using type conversion)
- import java.util.Scanner;
- class Problem4ew{
- public static void main(String args[]){
- Scanner sc=new Scanner(System.in);
- String s=sc.nextLine();
- char c;
- String output="";
- for (int i=0; i<s.length(); i++){
- c=(char)((int)(s.charAt(i)+32));
- output=output+c;
- }
- System.out.println(output);
- }
- }
- // Problem 5
- import java.util.Scanner;
- class Problem5{
- public static void main(String args[]){
- Scanner sc=new Scanner(System.in);
- String s=sc.nextLine();
- int num=s.length()/2, e=0;
- for (int i=0; i<num; i++){
- if (s.charAt(i)!=s.charAt(s.length()-i-1)){
- e++;
- }
- }
- if (e==0){
- System.out.print("Is a palindrome");
- }
- else {
- System.out.print("Is not a palindrome");
- }
- }
- }
- // Problem 6(i)
- import java.util.Scanner;
- class Problem6i{
- public static void main(String args[]){
- Scanner sc=new Scanner(System.in);
- int num=sc.nextInt();
- int prod=1;
- for (int i=2; i<=num; i++){
- prod*=i;
- }
- System.out.print(prod);
- }
- }
- // Problem 6(ii)
- import java.util.Scanner;
- class Problem6ii{
- public static void main(String args[]){
- Scanner sc=new Scanner(System.in);
- int num=sc.nextInt();
- int prod=1, i=1;
- while(num-->0){
- prod*=i;
- i++;
- }
- System.out.print(prod);
- }
- }
- // Problem 6(iii)
- import java.util.Scanner;
- class Problem6iii{
- public static void main(String args[]){
- Scanner sc=new Scanner(System.in);
- int num=sc.nextInt();
- int prod=1, i=1;
- do {
- prod*=i;
- i++;
- } while(num-->1);
- System.out.print(prod);
- }
- }
- // Problem 7
- import java.util.Scanner;
- class Problem7{
- public static void main(String args[]){
- Scanner sc=new Scanner(System.in);
- int num1=sc.nextInt();
- int num2=sc.nextInt();
- int num3=sc.nextInt();
- int max=(num1>num2)?((num1>num3)?num1:num3):((num2>num3)?num2:num3);
- System.out.print(max);
- }
- }
- // Problem 8
- import java.util.Scanner;
- class Problem8{
- public static void main(String args[]){
- Scanner sc=new Scanner(System.in);
- int num=sc.nextInt();
- int a[]=new int[num];
- for (int i=0; i<num; i++){
- a[i]=sc.nextInt();
- }
- int z=0;
- for (int i=0; i<num/2; i++){
- z=a[i];
- a[i]=a[num-1-i];
- a[num-1-i]=z;
- }
- for (int i=0; i<num; i++){
- System.out.print(a[i] + " ");
- }
- }
- }
- // Problem 9
- import java.util.Scanner;
- class Problem9{
- public static void main(String args[]){
- Scanner sc=new Scanner(System.in);
- int n=sc.nextInt();
- int a[][]=new int[n][n];
- for (int i=0; i<n; i++){
- for (int j=0; j<n; j++){
- a[i][j]=sc.nextInt();
- }
- }
- int e=0;
- for (int i=0; i<n; i++){
- for (int j=0; j<i; j++){
- if (a[i][j]!=0){
- e=1;
- }
- }
- }
- if (e==0){
- System.out.print("Given matrix is upper triangular");
- }
- else {
- System.out.print("Given matrix is not upper tringular");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement