Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
PE #4
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//Title of this code //'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_45 import java.util.*; import java.lang.*; class Rextester { public static void main(String args[]) { int prod = -1; boolean ans = false; int bigPalin = -1; // int i =0; for(int i=100; i<1000; i++) { for(int n =100; n<1000; n++) { prod = i*n; ans = isPalin(prod); //System.out.println(i+"*"+n+"="+prod); if(ans == true) { // System.out.println(""+prod+" was a palindrome"); if (prod > bigPalin) { bigPalin = prod; } } } } System.out.println(bigPalin); //System.out.println(isPalin(1001)); } public static boolean isPalin(int num) { String numstr = ""+num; String temp1 = ""; String temp2 = ""; boolean ans = true; int numlen = numstr.length(); //System.out.println("Diag 1. num: "+num+", numstr: "+numstr+", temp1: "+temp1+", temp2: "+temp2+", ans: "+ans+", numlen: "+numlen); for(int i=0; i<numlen/2; i++) { temp1 = numstr.substring(i, i+1); temp2 = numstr.substring(numlen-1-i, numlen-i); if(!(temp1.equals(temp2))) { ans = false; } // else { } // System.out.println("Loop #"+i+", temp1: "+temp1+", temp2: "+temp2); } //System.out.println("Diag 2. ans: "+ans); return ans; } }
[
+
]
Show input
Compilation time: 0.73 sec, absolute running time: 0.24 sec, cpu time: 0.29 sec, memory peak: 97 Mb, absolute service time: 0.98 sec
fork mode
|
history
|
discussion
906609